<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(faithwar) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
date_default_timezone_set("PRC"); //timezone
//$dateTime = date("Y-m-d",strtotime("-1 day"));
$handle = fopen("/usr/share/nginx/www/log/faithwar/log.txt", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);


    $id =  $arr["str2"];
    $id2 = $arr["d1"];
    $id3 = $arr["d2"];
    $id4 = $arr["targetCount"];
    $id5 = $arr["cityId"];
    $id6 = $arr["userId"];
    $id7 = $arr["action"];
    $id8 = $arr["targetId"];
    $id9 = $arr["gold"];
    $id10 = $arr["heroId"];
    $id11 = $arr["countryId"];
    $id12 = $arr["str1"];
    $id13 = $arr["actionDate"];
    $id14 = $arr["curLv"];//curLv

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
        
        $str2 = $id;
        $d1 = $id2;
        $d2 = $id3;
        $targetCount = $id4;
        $cityId = $id5;
        $deviceid = $id6;
        $action = $id7;
        $targetId = $id8;
        $gold = $id9;
        $heroId = $id10;
        $countryId = $id11;
        $str1 = $id12;
        $actionDate = $id13;
        $level = $id14;

    

        mysql_query("INSERT INTO faithwar_query (str2,d1,d2,targetCount,cityId,deviceid,action,targetId,gold,heroId,countryId,str1,createdate,date,level) 
                    VALUES('$str2','$d1','$d2','$targetCount','$cityId','$deviceid','$action','$targetId','$gold','$heroId','$countryId','$str1','$actionDate','$actionDate','$level')") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
